<?php
App::uses('PhpExcelHelper', 'View/Helper');

class PhpExcelRrdHelper extends PhpExcelHelper {
	public function __construct(View $view, $settings = array()) {
      parent::__construct($view, $settings);
   }

	public function addTableHeader($data, $params = array()){
		switch($params['h_align']){
			case 'center':
				$h_align = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
				break;
			case 'right':
				$h_align = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
				break;
			case 'left':
				$h_align = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
				break;
			case 'justify':
				$h_align = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
				break;
			case 'centerContinuous':
				$h_align = PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS;
				break;
			default:
				$h_align = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
		}
		switch($params['v_align']){
			case 'bottom' :
				$v_align = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
				break;
			case 'top' :
				$v_align = PHPExcel_Style_Alignment::VERTICAL_TOP;
				break;
			case 'justify' :
				$v_align = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY;
				break;
			default:
				$v_align = PHPExcel_Style_Alignment::VERTICAL_CENTER;
		}
		if(array_key_exists('h_align', $params)){
			$this->xls->getActiveSheet()->getStyle($this->row)->getAlignment()->setHorizontal($v_align);
		}
		if(array_key_exists('v_align', $params)){
			$this->xls->getActiveSheet()->getStyle($this->row)->getAlignment()->setVertical($h_align);
		}
		parent::addTableHeader($data, $params);
	}
	
	public function addTableRow($data, $params){
		$this->xls->getActiveSheet()->getStyle($this->row)->applyFromArray($params);
		parent::addTableRow($data);
	}
}